<?php
require_once 'vendor/autoload.php';

use app\model\OperationLog;

// 初始化应用
$app = new \think\App();
$app->initialize();

echo "测试日志系统...\n";

// 测试记录日志
$logData = [
    'user_id' => 1,
    'username' => 'admin',
    'action' => '用户登录',
    'module' => '用户认证',
    'description' => '用户admin登录系统',
    'request_method' => 'POST',
    'request_url' => 'http://localhost:8000/api/auth/login',
    'request_params' => json_encode(['username' => 'admin'], JSON_UNESCAPED_UNICODE),
    'response_code' => 200,
    'response_message' => '登录成功',
    'ip_address' => '127.0.0.1',
    'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
    'execution_time' => 0.123,
    'status' => 'success'
];

try {
    $result = OperationLog::record($logData);
    echo "记录日志结果: " . ($result ? '成功' : '失败') . "\n";
    
    // 测试获取日志列表
    $logs = OperationLog::getLogList(['limit' => 5]);
    echo "获取日志列表: " . count($logs['list']) . " 条记录\n";
    
    // 测试统计功能
    $moduleStats = OperationLog::getModuleStats();
    echo "模块统计: " . count($moduleStats) . " 个模块\n";
    
    $statusStats = OperationLog::getStatusStats();
    echo "状态统计: " . count($statusStats) . " 种状态\n";
    
    echo "日志系统测试完成！\n";
    
} catch (Exception $e) {
    echo "错误: " . $e->getMessage() . "\n";
} 